<template>
	<view class="sales-page">
		<view class="item-wrap flex-row" v-for="(item,index) in list" @click="onCheck(item,index)">
				<checkbox :checked="index==current"/>
				<view class="prod-wrap flex-row">
					<image :src="item.pic" />
					<view class="prod-r">
						<view class="prod-text">{{item.prodName}}</view>
						<view class="prod-text prod-price">￥{{item.price}}</view>
					</view>
				</view>
		</view>
		<button class="confirm" @click="onConfirm">确定</button>
	</view>
</template>

<script>
	import config from '../../common/config.js'
	export default {
		data() {
			return {
				list:[],
				current:-1,
				prod:{}
			}
		},
		onLoad() {
			let res = uni.getStorageSync('userId')
			console.log('res:',res)
			this.loadData()
		},
		methods: {
			//获取商品列表
			loadData() {
				uni.request({
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
					},
					url: config.mallHost + '/prod/prodListByTagId', //仅为示例，并非真实接口地址。
					method: 'GET',
					data:{tagId: 2,size: 6},
					success: (res) => {
						console.log('商品：', res);
						this.list = res.data.records
					},
					fail: (error) => {
						console.log(error)
					}
				});
			},
			onCheck(item,index){
				this.current = index
				this.prod = item
			},
			onConfirm(){
				const pages = getCurrentPages()
				const prevPage = pages[pages.length - 2]
				const params = this.prod
				prevPage.$vm.selectProd(params)
				uni.navigateBack({
					delta:1
				})
			}
			
		}
	}
</script>

<style>
	.flex-row{
		display: flex;
		align-items: center;
	}
	.sales-page .item-wrap{
		background-color: white;
		margin-top: 30upx;
		padding: 20upx 30upx;
	}
	.sales-page .prod-wrap {
		margin-left: 30upx;
	}
	.sales-page .prod-wrap image{
		height: 120upx;
		width: 120upx;
	}
	.prod-r{
		margin-left: 30upx;
	}
	.prod-text{
		font-size: 28upx;
	}
	.prod-price{
		color: firebrick;
		margin-top: 30upx;
	}
	.sales-page .confirm{
		width: 80%;
		height: 80upx;
		line-height: 80upx;
		color: white;
		background: linear-gradient(#F1C75E, #d4a93c);
		font-size: 32upx;
		border-radius: 10upx;
		margin: 30upx auto;
	}
</style>
